package com.zhuxiang.test1;

import java.io.Serializable;

/**
 * 定义学生类
 * 学生的信息有：学号、姓名、年龄
 */
public class Student implements Serializable {

    private static final long serialVersionUID = -686008340237112114L;
    private int id;
    private String name;
    private int age;

    public Student() {
    }

    public Student(int id, String name, int age) {
        setId(id);
        this.name = name;
        setAge(age);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        if (id < 0){
            try {
                throw new IdException("输入的学号有误！");
            } catch (IdException e) {
                e.printStackTrace();
            }
        }else {
            this.id = id;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age <= 0 || age >=100){
            try {
                throw new AgeException("输入的年龄有误");
            } catch (AgeException e) {
                e.printStackTrace();
            }
        }else {
            this.age = age;
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
